package com.xsherl.leetcode.solution;

import com.xsherl.leetcode.base.TreeNode;
import com.xsherl.leetcode.utils.PrintUtils;
import com.xsherl.leetcode.utils.TreeUtils;

import java.util.ArrayList;
import java.util.List;

public class BinaryTreeInorderTraversal {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        inorderTraversal(root, res);
        return res;
    }

    public void inorderTraversal(TreeNode root, List<Integer> res) {
        if (root == null){
            return;
        }
        inorderTraversal(root.left, res);
        res.add(root.val);
        inorderTraversal(root.right, res);
    }

    public static void main(String[] args) {
        Integer[] nums = {1,null,2,3};
        TreeNode root = TreeNode.buildTree(nums);
        PrintUtils.println(root);
        List<Integer> list = new BinaryTreeInorderTraversal().inorderTraversal(root);
        System.out.println(list);
    }

}
